## base data struct

class ListNode():
    def __init__(self,x):
        self.val = x # 一个节点的值
        self.next = None # 一个节点的

def list_2_ListNode(nums):
    '''
    将数组转成链表
    :param nums:
    :return:
    '''
    head = ListNode(nums[0])
    cur = head
    for num in nums[1:]:
        newnode = ListNode(num)
        cur.next = newnode
        # 更新cur：
        cur = newnode
    return head # 获取链表的方式是获取头节点

def tranverse_listnode(head):
    '''
    遍历链表
    '''
    cur = head
    while cur:
        print(f"当前链表节点值为{cur.val}")
        cur = cur.next

def make_circle_listnode(nums:list,start:int,end:int)->ListNode:
    '''
    构造环形链表
    :param nums: 数组
    :param n: 环的位置索引，从0开始
    :return:
    '''
    if end>start:
        raise ValueError('环的终点索引必须小于起点，否则不是环')
    head = ListNode(nums[0])
    cur = head
    lenth = 1
    for num in nums[1:]:
        newnode = ListNode(num)
        cur.next = newnode
        # 更新cur：
        cur = newnode
        lenth+=1
    circle_p = head
    # 然后需要
    for i in range(lenth):
        if i == start:
            start_listnode = circle_p
        if i == end:
            end_listnode = circle_p
        circle_p=circle_p.next
    start_listnode.next=end_listnode
    return head

if __name__=="__main__":
    res = make_circle_listnode([1,2,3,4,5,6],4,3)
    tranverse_listnode(res)




